//
//  TicketViewController.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/17.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "TicketViewController.h"
#import "UIButton+Dzm.h"
#import "TicketCell.h"
#import "BottomView.h"
#import "SaleTicketViewModel.h"

@interface TicketViewController ()
@property (strong, nonatomic) SaleTicketViewModel *saleTicketViewModel;


@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UITextField *inputTextField;

@property (weak, nonatomic) IBOutlet UIButton *addTicketBtn;

- (IBAction)addTicketAction:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITableView *mainTable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainTable_bottom;

@end

@implementation TicketViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.saleTicketViewModel = [[SaleTicketViewModel alloc ] init];
    
    [self setLeftBtnItem];
    
    // 如果可以选择
    if (self.isSelect) {
        [CommoneTools changeConstraintView:self.topView constraintHeight:0.1];
        [self.topView setHidden:YES];
        [self createBottomBtn];
       self.mainTable_bottom.constant = 60;
    }else{
        self.inputTextField.layer.cornerRadius = 3;
        self.inputTextField.layer.masksToBounds=YES;
        self.inputTextField.leftView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 10, 10)];
        self.inputTextField.leftViewMode = UITextFieldViewModeAlways;
        [self.inputTextField setValue:GLOBLE_GRAY_COLOR_3 forKeyPath:@"_placeholderLabel.textColor"];
        [self.addTicketBtn styleButton];
        self.mainTable.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    }
}

#pragma mark ---------------下方按钮------------------
-(void)createBottomBtn{
    NSMutableArray *bottomList = [[NSMutableArray alloc ] init];
     [bottomList addObject:@"不使用优惠券"];
    WEAKSELF
    BottomView *bottomView = [[BottomView alloc ] initWithStatusArray:bottomList callBlcok:^(NSInteger index) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    
    UIView *view =  [[UIView alloc ] initWithFrame:CGRectMake(0, [UIScreen height] - 124, [UIScreen width], 60)];
    [view addSubview:bottomView];
    [self.view addSubview:view];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isSelect) {
        
        if ([self.delegate respondsToSelector:@selector(selectedTicket:)]) {
            [self.delegate selectedTicket:@"15"];
        }
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TicketCell *ticketCell = [tableView dequeueReusableCellWithIdentifier:@"TicketCell"];
    [ticketCell show:indexPath];
    return ticketCell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)addTicketAction:(UIButton *)sender {
    
    
}
@end
